var RegNumber	= url.templateArgs["RegNumber"];
var RecName 	= url.templateArgs["RecName"];
var RegTitle	= url.templateArgs["RegTitle"];
var RegNote 	= url.templateArgs["RegNote"];
var Initiator 	= url.templateArgs["Initiator"];
var Mode 		= url.templateArgs["Mode"];
var Documents	= url.templateArgs["Attachments"];

var site = "sakym-personalo-klausimais-registravimas";
var datalistRef = "25414011-ca88-489e-94b2-c9f032cdfc26";
var uri = "Sites/" + site + "/dataLists/" + datalistRef;

var referenceType = "node";
var data = new Date();

function returnNode(node){
    var reference = ["workspace", "SpacesStore", node];
    var foundNode = search.findNode(referenceType, reference);
    return foundNode;
}

var personaloPazymuList = companyhome.childByNamePath(uri); 
var DocArray = Documents.split("|");

var iras = personaloPazymuList.createNode(null, "rcc:personaloPazymuList");
iras.properties["rcc:perPazGavPav"] = RecName;
iras.properties["rcc:perPazRegNumeris"] = RegNumber;
iras.properties["rcc:perPazRegData"] = data;
iras.properties["rcc:perPazRegTitle"] = RegTitle;
iras.properties["rcc:perPazRegNote"] = RegNote;
iras.save();
//iras.createAssociation(person,"rcc:perPazAssignedTo");
iras.createAssociation(person,"rcc:perPazRegistrator");

var iniciator= people.getPerson(Initiator);
if (iniciator != null && iniciator != "" && iniciator != "undefined") {
    iras.createAssociation(iniciator,"rcc:perPazIniciator");
}

for (var i=0;i<DocArray.length;i++){
    iras.createAssociation(returnNode(DocArray[i]),"rcc:perPazAttachments");
}

if (iras.nodeRef != null) {
    status.code=200;
    model.message= "success";
} else {
    status.redirect=true;
    status.code=404;
    model.message= "error";
}